package com.spider.spiderorderbasedata.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.spider.spiderorderbasedata.model.entity.RequestClass;
import com.spider.spiderorderbasedata.service.RequestClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author xiong.bo
 * @version 1.0
 * @date 2024/5/12 11:03 上午
 */

@Api(tags = "请求类控制器")
@Slf4j
@RestController
@RequestMapping("/requestClass")
public class RequestClassContoller {

    @Autowired
    private RequestClassService requestClassService;

    @ApiOperation("请求类列表")
    @GetMapping
    public ResponseEntity<IPage<RequestClass>> selectPage(@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int pageSize) {
        return ResponseEntity.ok(requestClassService.selectPage(page, pageSize));
    }

    @ApiOperation("查询请求类详情")
    @GetMapping("/{id}")
    public ResponseEntity<RequestClass> findById(@PathVariable Long id) {
        return ResponseEntity.ok(requestClassService.findById(id));
    }


    @ApiOperation("新增请求类主表")
    @PostMapping
    public ResponseEntity<RequestClass> saveLocation(@RequestBody RequestClass requestClass) {
        return ResponseEntity.ok(requestClassService.saveRequestClass(requestClass));
    }

    @ApiOperation("编辑请求类主表")
    @PutMapping
    public ResponseEntity<RequestClass> editLocation(@RequestBody RequestClass requestClass) {
        return ResponseEntity.ok(requestClassService.editRequestClass(requestClass));
    }

    @ApiOperation("删除某条请求类主表")
    @DeleteMapping("/{id}")
    public ResponseEntity<Boolean> deleteLocation(@PathVariable Long id) {
        return ResponseEntity.ok(requestClassService.deleteRequestClass(id));
    }


}
